unit App.Action.TAppDefaultChildActionViewOpenAction;

interface

uses SmallStruct.Action,
  App.Action.TAppCustomeAction;

type
  TAppDefaultChildActionViewOpenAction = class(TAppCustomeAction)
  protected
    function DoPerform(ActionContext: ISSActionContext): Boolean; override;
  end;

implementation

uses SysUtils,
  SmallStruct.Configuration,
  SmallStruct.Tools;

{ TAppDefaultChildActionViewOpenAction }

function TAppDefaultChildActionViewOpenAction.DoPerform(ActionContext: ISSActionContext): Boolean;
var
  KeyFieldName: string;
  Index: Integer;
  ModelConfiguration: ISSModelConfiguration;
  OpenCondition: TSSRecord;
begin
  Result := False;
  if GetRequestViewPrimaryDataModel.GetDataSet.GetCount < 1 then
    Exit;
  GetResponseViewPrimaryDataModel.CloseDataModel;

  ModelConfiguration := GetRequestViewPrimaryDataModel.GetContext.GetConfiguration as ISSModelConfiguration;

  for Index := 0 to ModelConfiguration.GetFieldConfiguration.GetCount - 1 do
    if (ModelConfiguration.GetFieldConfiguration.GetObject(Index) as ISSModelFieldConfiguration).IsPrimaryKey then
    begin
      KeyFieldName := (ModelConfiguration.GetFieldConfiguration.GetObject(Index) as ISSModelFieldConfiguration).GetFieldName;
      Break;
    end;

  OpenCondition := TSSRecord.Create(Self);

  OpenCondition.AppendValue(KeyFieldName, GetRequestViewPrimaryDataModel.GetDataSet.GetIntegerValue(KeyFieldName));

  ActionContext.GetResponseView.GetContext.GetParameter.AppendObject('OPEN_CONDITION', OpenCondition);

  GetResponseViewPrimaryDataModel.OpenDataModel(KeyFieldName + '=' + IntToStr(GetRequestViewPrimaryDataModel.GetDataSet.GetIntegerValue(KeyFieldName)));

  Result := True;
end;

end.
